package com.wwwarehouse.resource_center.fragment.createobject.creategoods;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.view.View;

import com.wwwarehouse.resource_center.adapter.rules.MyPagerAdapter;
import com.wwwarehouse.resource_center.bean.goods.GoodsAttributesBean;
import com.wwwarehouse.resource_center.eventbus_event.RulesEvent;
import com.wwwarehouse.resource_center.fragment.base.MyBaseViewPagerFragment;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * @author Joseph on 2017/9/23.
 *         <p/>
 *         已经选择的属性编辑
 */

public class GoodsAttributesHaveChosenSelectParentFragment extends MyBaseViewPagerFragment {

    List<GoodsAttributesBean.ListBean> mSelectList  = new ArrayList<>();
    ArrayList<Fragment> fragmentList;
    MyPagerAdapter mAdapter;
    int mNum = 24;
    @Override
    protected void loadDatas() {
        mConfirmBtn.setVisibility(View.VISIBLE);
        mConfirmBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new RulesEvent(1, "notify-Have-Chosen")); //通知主页面刷新
                popFragment();
            }
        });
        Bundle bundle = getArguments();
//        GoodsAttributesBean.ListBean  bean ;
//        for (int i = 0; i <53 ; i++) {
//            bean = new GoodsAttributesBean.ListBean();
//            bean.setAttributeName("测试"+i);
//            mSelectList.add(bean);
//        }
        if (null!=bundle){
            mSelectList = bundle.getParcelableArrayList("mSelectList");
        }
        fragmentList = new ArrayList<>();
        int count = 0;
        if (mSelectList.size() > mNum) {
            if ((mSelectList.size() - mNum) % mNum == 0) {
                count = (mSelectList.size() - mNum) / mNum;
            } else {
                count = (mSelectList.size() - mNum) / mNum + 1; // 总共显示多少张卡片
            }
        } else {
            count = 0;
        }
        for (int i = 0; i <= count; i++) {
            GoodsAttributesHaveChosenSelectChildFragment categoryFragment = new GoodsAttributesHaveChosenSelectChildFragment();
            Bundle b = new Bundle();
            b.putParcelableArrayList("data", (ArrayList<? extends Parcelable>) mSelectList);
            b.putInt("pos", i);
            b.putInt("num", mNum);
            categoryFragment.setArguments(b);
            fragmentList.add(categoryFragment);
        }
        mAdapter = new MyPagerAdapter(getChildFragmentManager(), fragmentList);
        mCustomPager.setAdapter(mAdapter);
        mPagerInternal.setViewPager(mCustomPager, 0);
    }
}
